<?php

define('TASK_OK', 0);
define('TASK_FAILED', 10);
define('TASK_INVALID', 1);

class Task {

    public static function notifyLeaked($user_id, $release_id) {

        try {

            $tmp_user = User::getById($user_id);
            $tmp_release = Release::getById($release_id);

            if($tmp_user instanceof User && $tmp_release instanceof Release) {

                // Notifying
                $result = Notifier::notify('Album leak notification', $tmp_user->email, 'leak.notice.txt', $tmp_user->lang, array('release' => &$tmp_release, 'user' => &$tmp_user));

                if($result === true)
                    return TASK_OK;
                else
                    return TASK_FAILED;

            }

        } catch (Exception $e) {

            return TASK_INVALID;
        }
    }

    public static function notifyRelease($user_id, $release_id) {

        try {

            $tmp_user = User::getById($user_id);
            $tmp_release = Release::getById($release_id);

            if($tmp_user instanceof User && $tmp_release instanceof Release) {

                // Notifying
                $result = Notifier::notify('Release notification', $tmp_user->email, 'release.notice.txt', $tmp_user->lang, array('release' => $tmp_release, 'user' => $tmp_user));

                if($result === true)
                    return TASK_OK;
                else
                    return TASK_FAILED;

            }

        } catch (Exception $e) {

            return TASK_INVALID;
        }
    }

    public static function notifyArtist($user_id, $artist_id) {

        try {

            $tmp_user = User::getById($user_id);
            $tmp_artist = Artist::getById($artist_id);

            if($tmp_user instanceof User && $tmp_artist instanceof Artist) {

                // Notifying
                $result = Notifier::notify('Artist release notification', $tmp_user->email, 'artist.notice.txt', $tmp_user->lang, array('release' => &$tmp_artist, 'user' => &$tmp_user));

                if($result === true)
                    return TASK_OK;
                else
                    return TASK_FAILED;

            }

        } catch (Exception $e) {

            return TASK_INVALID;
        }
    }
}